package leetcode.editor.cn;

public class _98_ValidateBinarySearchTree {
    public static void main(String[] args) {
        Solution solution = new _98_ValidateBinarySearchTree().new Solution();
    }
    //leetcode submit region begin(Prohibit modification and deletion)

    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

    class Solution {

        public boolean isValidBST(TreeNode root, long lowLimit, long upLimit) {
            if (root == null) {
                return true;
            }
            return root.val < upLimit && root.val > lowLimit && isValidBST(root.left, lowLimit, root.val) && isValidBST(root.right, root.val, upLimit);
        }


        public boolean isValidBST(TreeNode root) {
            long lowLimit = Long.MIN_VALUE, upLimit = Long.MAX_VALUE;
            return isValidBST(root, lowLimit, upLimit);
        }
    }

//leetcode submit region end(Prohibit modification and deletion)

}